﻿using System;
using fastCSharp;

namespace diantou.dataModel
{
    /// <summary>
    /// 考试问题数据
    /// </summary>
    public class examQuestionBase
    {
        /// <summary>
        /// 客户端导入标识
        /// </summary>
        public int ClientId;
        /// <summary>
        /// 单选题答案索引(从0开始)
        /// </summary>
        public int Answer;
        /// <summary>
        /// 考试类型
        /// </summary>
        public enum type : byte
        {
            None,
            /// <summary>
            /// 单选题
            /// </summary>
            Radio,
            /// <summary>
            /// 多选题
            /// </summary>
            MultipleChoice,
            /// <summary>
            /// 问答题
            /// </summary>
            Question,
            /// <summary>
            /// 编程题
            /// </summary>
            Problem
        }
        /// <summary>
        /// 考试类型
        /// </summary>
        public type Type;
        /// <summary>
        /// 多选题答案索引集合，比如 0,2
        /// </summary>
        [fastCSharp.emit.dataMember(MaxStringLength = 32, IsAscii = true)]
        public string AnswerContent = string.Empty;

        /// <summary>
        /// 描述
        /// </summary>
        [fastCSharp.emit.dataMember(MaxStringLength = 16 << 10)]
        public string Description = string.Empty;
        /// <summary>
        /// 选择题答案选项
        /// </summary>
        [fastCSharp.emit.dataMember(MaxStringLength = 4 << 10)]
        public fastCSharp.sql.jsonMember<string[]> Answers = string.Empty;

        /// <summary>
        /// 数据检测
        /// </summary>
        /// <returns></returns>
        public bool Check(type type)
        {
            if (Type == type.None) Type = type;
            switch (Type)
            {
                case type.Radio:
                    return Answers.Value.length() > 1 && (uint)Answer < Answers.Value.Length;
                case type.MultipleChoice:
                    return Answers.Value.length() != 0 && AnswerContent.length() != 0;
            }
            return false;
        }
    }
    /// <summary>
    /// 考试问题
    /// </summary>
    [fastCSharp.emit.jsonSerialize(IsAllMember = true)]
    [fastCSharp.emit.jsonParse(IsAllMember = true)]
    [fastCSharp.emit.dataSerialize(IsReferenceMember = false)]
    [fastCSharp.code.cSharp.webView.clientType(Name = "diantou.examQuestion")]
    [fastCSharp.code.cSharp.sqlModel(LogTcpCallService = "ExamDataLog")]
    public partial class examQuestion : examQuestionBase
    {
        /// <summary>
        /// 考试问题标识+考试类型
        /// </summary>
        public struct questionType : IEquatable<questionType>
        {
            /// <summary>
            /// 考试问题标识
            /// </summary>
            public int QuestionId;
            /// <summary>
            /// 考试类型
            /// </summary>
            public type Type;
            /// <summary>
            /// 关键字比较
            /// </summary>
            /// <param name="other">关键字</param>
            /// <returns>是否相等</returns>
            public bool Equals(questionType other)
            {
                return ((QuestionId ^ other.QuestionId) | ((byte)Type ^ (byte)other.Type)) == 0;
            }
            /// <summary>
            /// 哈希编码
            /// </summary>
            /// <returns></returns>
            public override int GetHashCode()
            {
                return QuestionId.GetHashCode() ^ ((int)(byte)Type << 24);
            }
            /// <summary>
            /// 关键字比较
            /// </summary>
            /// <param name="obj"></param>
            /// <returns></returns>
            public override bool Equals(object obj)
            {
                return Equals((questionType)obj);
            }
        }
        /// <summary>
        /// 考试问题标识
        /// </summary>
        [fastCSharp.code.cSharp.webView.outputAjax]
        public int Id;
        /// <summary>
        /// 用户标识
        /// </summary>
        public int UserId;
        /// <summary>
        /// 单选题分数
        /// </summary>
        public const int RadioPoint = 5;
        /// <summary>
        /// 多选题分数
        /// </summary>
        public const int MultipleChoicePoint = 10;
        /// <summary>
        /// 分数
        /// </summary>
        public int Point;
        /// <summary>
        /// 独占企业用户标识(无效)
        /// </summary>
        public int EnterpriseId;
        /// <summary>
        /// 是否企业独占(无效)
        /// </summary>
        public bool IsPrivate;
        /// <summary>
        /// 是否公共题库
        /// </summary>
        public bool IsPublic;
        /// <summary>
        /// 是否发布显示
        /// </summary>
        public problem.showType ShowType = problem.showType.None;
        /// <summary>
        /// 添加时间
        /// </summary>
        public DateTime SubmitTime;
        /// <summary>
        /// 第一次发布时间
        /// </summary>
        public DateTime FristTime = fastCSharp.pub.MinTime;
        /// <summary>
        /// 发布时间
        /// </summary>
        public DateTime ShowTime = fastCSharp.pub.MinTime;
        /// <summary>
        /// 自动发布时间
        /// </summary>
        //[fastCSharp.emit.dataMember(DefaultValue = "'1900/1/1'")]
        public DateTime AutoShowTime = fastCSharp.pub.MinTime;

        /// <summary>
        /// 选用数量
        /// </summary>
        [fastCSharp.emit.dataMember(IsIgnoreCurrent = true, IsSqlStream = true)]
        public int UsedCount;
        /// <summary>
        /// 话题数量
        /// </summary>
        [fastCSharp.emit.dataMember(IsIgnoreCurrent = true, IsSqlStream = true)]
        public int TopicCount;

        /// <summary>
        /// 考试题号
        /// </summary>
        [fastCSharp.emit.dataMember(IsIgnoreCurrent = true)]
        public byte ExamIndex;
        /// <summary>
        /// 考试题目类型数量
        /// </summary>
        public static readonly int TypeSize = fastCSharp.Enum.GetMaxValue<type>(-1) + 1;
    }
}
